package zip;

/**
 * Created by jinju on 2016/5/5.
 */
public class UnZipPassword {
    private char[] chars ;

    private int len;

    private CharEnum[] password;

    private CharEnum[] values;

    public UnZipPassword(int len) {
        this.len = len;
    }

    public void create() {
        this.values = CharEnum.values();
        password = new CharEnum[len];
        chars =new char[len];
        for (int i = 0; i < len; i++) {
            password[i] = values[0];
            chars[i]  =values[0].getVal();
        }
    }

    public String getPassword() {
        if (null == password) {
            this.create();
        }

        return new String(chars);
    }

    public void next(){
        CharEnum charEnum = null;
        for (int i = len - 1; i >= 0; i--) {
            charEnum = password[i];
            if (charEnum.ordinal() == values.length - 1) {
                password[i] = values[0];
                chars[i] = values[0].getVal();
            }else{
                password[i] = values[charEnum.ordinal() + 1];
                chars[i] = values[charEnum.ordinal() + 1].getVal();
                break;
            }
        }
    }

}
